<?php
/**
 * StarController.php
 * 
 * Create on 2015-04-02
 * Create by yuebin
 */
namespace haibao\cms\business\control\pc\index;

use haibao\cms\business\control\PublicController as PublicControllerBusiness;
use haibao\cms\business\control\pc\entity\ArticleEntity;
class StarController extends IndexController{

	const STARS_TAG = 1383;
	const STARS_BLOG_CATEGORY = 92;
	/**
	 * 身份/职业
	 */
	private static $starTypesArr = array(
			'1'=>"名人名流",
			'2'=>"影视明星",
			'3'=>"模特",
			'4'=>"歌手/乐队",
			'5'=>"体育明星",
			'6'=>"时尚博主",
			'7'=>"时尚编辑",
			'8'=>"It Girl",
			'9'=>"王室成员",
			'10'=>"明星宝贝",
			'11'=>"风格偶像",
			'12'=>"美剧明星",
			'15'=>"设计师",
			'13'=>"其他"
	);
	
	public function __construct($updateTime = null,$controlId,$isPublish){
		$this->conditionTagId = self::STARS_TAG;
		parent::__construct($updateTime,$controlId,$isPublish);
	}
	
	/**
	 * 显示模版内容（模版动态数据的绑定和模版输出）
	 * @param : String $content
	 * @param : Array $controlData;
	 */
	public function displayTemplateHtml(){

		$controlData = $this->getParameter(self::$CONTROL_DATA);
		$content = $this->getParameter(self::$CONTROL_CONTENT);
		if($controlData['manual']){
			// 第一屏
			$this->getFirstActualData($controlData['manual']);
		}

		$this->assign('attentionType', \haibao\www\model\data\Favorite::ATTENTION_TYPE_STAR);
		$this->assign('hostUrl', \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_BOZHU));
		$this->assign('moreUrl', \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_STAR).'/stars/2272/');

		
		// 处理keywords
		$this->assign('tagInfo', PublicControllerBusiness::getKeyWordsByChannel($this->conditionTagId,$this->tagUrl));
		
		$this->assign('wordLinkList',$this->getWordLinkList($controlData['auto'],self::getTagChannel($this->conditionTagId)));
		
		$this->assign('starUrl', \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_STARS));
		$this->assign('channelUrl', \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_STAR));
		$starType = self::$starTypesArr;
		$this->assign('starType',$starType);
		$path = $this->generateHtmlPath(__CLASS__);
		$isNewHtml = $this->generateHtml($path,$content);

		$content = $this->getHtml($path);
		$content = $this->replaceCDNLink($content);
		return $content;
	}
	
	/**
	 * 获取明星模版第一屏文章数据
	 * @param : $dataCondition 数据条件
	 */
	public function getFirstActualData($dataCondition){
		
		$articleEntity = new ArticleEntity();
		$articleEntity->setLevel($dataCondition['level']);
		$articleEntity->setBigLevel($dataCondition['biglevel']);
		$articleEntity->setLimit($dataCondition['limit']);
		$articleEntity->setIsProImage(true);
		$articleEntity->setIsLeftJoinTag(true);
		$articleEntity->setIsPrimaryTag(false);
		$articleEntity->setIsConditionTag(true);
		$articleEntity->setIsReturnTag(true);
		$articleEntity->setIsImageColl(true);
		$articleEntity->setSource(__CLASS__);
		$articleEntity->setTagIds($this->conditionTagId);
		$articleEntity->setIsDebug(false);
		$articleEntity->setIsOnlyReturnPrimaryTag(true);
		$articleEntity->setProImageLevel(array(\haibao\cms\model\data\ArticleProImage::Level_FIVE,\haibao\cms\model\data\ArticleProImage::Level_SEVEN));
		
		$this->articleAction->setArticleEnity($articleEntity);
		list($articles,$imageColls) = $this->articleAction->getListForNew();
		
		$mergeData = $this->mergeData($articles['list'],$imageColls['list'],$articleEntity->getLimit());
		list($firstLeftArticle,$firstRightArticle) = $this->packageMergeData(self::PACKAGE_DATA_TYPE_INDEX_TREND_OR_STAR, $mergeData, $articles, $imageColls);
		
		$this->assign('firstLeftArticle',json_decode(json_encode(array_values($firstLeftArticle))));
		$this->assign('firstRightArticle', json_decode(json_encode(array_values($firstRightArticle))));
	}
}